<?php get_header(); ?>
<div class="containerwrap">
<div class="inner">
    <div class="container">
    <?php
    $enable_builder = get_post_meta($post->ID, 'mom_enable_builder', true);
    $builder_layout = get_post_meta($post->ID, 'mom_page_layout', true);
    ?>
    <?php if($enable_builder) { ?>
    <?php if($builder_layout == "leftside") { ?>
        <div class="main rightmain">
        <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
        <?php the_content(); ?>
	<div class="clear"></div>
	<?php wp_link_pages(); ?> 
    	<?php endwhile; else: ?>
	<?php endif; ?>        
    <?php wp_reset_query(); ?>
    </div> <!--end main -->
       <aside class="sidebar leftside">
	 <?php global $wp_query; $postid = $wp_query->post->ID; $cus = get_post_meta($postid, 'sbg_selected_sidebar_replacement', true);?>
	<?php if ($cus != '') { ?>
        <?php if ($cus[0] != '0') { ?>
             <?php if  (function_exists('dynamic_sidebar') && dynamic_sidebar($cus[0])){ }else { ?>
        	<p class="noside"><?php _e('There Is No Sidebar Widgets Yet', 'theme'); ?></p>
         <?php } ?>
	<?php } else { ?>
         <?php if  (function_exists('dynamic_sidebar') && dynamic_sidebar('Main sidebar')){ }else { ?>
        	<p class="noside"><?php _e('There Is No Sidebar Widgets Yet', 'theme'); ?></p>
         <?php } ?>
	<?php } ?>
        <?php } else { ?>
         <?php if  (function_exists('dynamic_sidebar') && dynamic_sidebar('Main sidebar')){ }else { ?>
        	<p class="noside"><?php _e('There Is No Sidebar Widgets Yet', 'theme'); ?></p>
         <?php } ?>
    <?php } ?>
    </aside> <!--End Sidebar-->
    <?php } elseif($builder_layout =="fullwidth") { ?>
	<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
        <div class="full_width_page_builder">
	<?php the_content(); ?>
	</div><!-- End Full width-->
	<div class="clear"></div>
	<?php wp_link_pages(); ?> 
    	<?php endwhile; else: ?>
	<?php endif; ?>        
    <?php wp_reset_query(); ?>

    <?php } else { ?>
        <div class="main">
        <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
        <?php the_content(); ?>
	<div class="clear"></div>
	<?php wp_link_pages(); ?> 
    	<?php endwhile; else: ?>
	<?php endif; ?>        
    <?php wp_reset_query(); ?>
    </div> <!--end main -->
       <aside class="sidebar">
	 <?php global $wp_query; $postid = $wp_query->post->ID; $cus = get_post_meta($postid, 'sbg_selected_sidebar_replacement', true);?>
	<?php if ($cus != '') { ?>
        <?php if ($cus[0] != '0') { ?>
             <?php if  (function_exists('dynamic_sidebar') && dynamic_sidebar($cus[0])){ }else { ?>
        	<p class="noside"><?php _e('There Is No Sidebar Widgets Yet', 'theme'); ?></p>
         <?php } ?>
	<?php } else { ?>
         <?php if  (function_exists('dynamic_sidebar') && dynamic_sidebar('Main sidebar')){ }else { ?>
        	<p class="noside"><?php _e('There Is No Sidebar Widgets Yet', 'theme'); ?></p>
         <?php } ?>
	<?php } ?>
        <?php } else { ?>
         <?php if  (function_exists('dynamic_sidebar') && dynamic_sidebar('Main sidebar')){ }else { ?>
        	<p class="noside"><?php _e('There Is No Sidebar Widgets Yet', 'theme'); ?></p>
         <?php } ?>
    <?php } ?>
    </aside> <!--End Sidebar-->
	<?php } //end builder layout ?>
    <?php } else { ?>
    <div class="main">
	<?php the_breadcrumb(); ?>
    <div class="box_outer">
	<article class="cat_article">
	        <h1 class="cat_article_title page_title"><?php the_title(); ?></h1>
    <div class="single_article_content">
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
        <?php the_content(); ?>
	<div class="clear"></div>
	<?php wp_link_pages(); ?> 
	<?php endwhile; else: ?>
	<?php endif; ?>
     <?php wp_reset_query(); ?>
   </div> <!--Single Article content-->
   <?php if(get_post_meta($post->ID, 'mom_page_comments', true)) { ?>
    <div class="dots"></div>
    <?php comments_template(); ?>
   <?php } ?>
    </article> <!--End Single Article-->
    </div> <!--Box Outer-->
    </div> <!--End Main-->
        <aside class="sidebar">
	 <?php global $wp_query; $postid = $wp_query->post->ID; $cus = get_post_meta($postid, 'sbg_selected_sidebar_replacement', true);?>
	<?php if ($cus != '') { ?>
        <?php if ($cus[0] != '0') { ?>
             <?php if  (function_exists('dynamic_sidebar') && dynamic_sidebar($cus[0])){ }else { ?>
        	<p class="noside"><?php _e('There Is No Sidebar Widgets Yet', 'theme'); ?></p>
         <?php } ?>
	<?php } else { ?>
         <?php if  (function_exists('dynamic_sidebar') && dynamic_sidebar('Main sidebar')){ }else { ?>
        	<p class="noside"><?php _e('There Is No Sidebar Widgets Yet', 'theme'); ?></p>
         <?php } ?>
	<?php } ?>
        <?php } else { ?>
         <?php if  (function_exists('dynamic_sidebar') && dynamic_sidebar('Main sidebar')){ }else { ?>
        	<p class="noside"><?php _e('There Is No Sidebar Widgets Yet', 'theme'); ?></p>
         <?php } ?>
    <?php } ?>
    </aside> <!--End Sidebar-->
    <?php } //end else page builder ?>
    </div> <!--End Container-->
 <?php get_footer(); ?>